package tests;

import java.util.HashMap;

import junit.framework.Assert;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import commands.AddStudent;

import containers.StudentContainer;
import entities.CoSigner;
import entities.FinancialInfo;
import entities.Loan;
import entities.Student;

/**
 * Tests for the addStudent command
 * 
 * @author gke703
 */
public class TestApplication {

	/**
	 * initialise student container
	 */
	@BeforeClass
	public static void Initialize() {
		// initialize student container
		StudentContainer.dictionary();

	}

	/**
	 * test adding students
	 */
	@Test
	public void testAddingStudent() {
		HashMap<Integer, Student> dictionary = StudentContainer.dictionary();

		Student student1 = new Student(123456, "123456");
		student1.setAddress("123 Fake St");
		student1.setBirthdate("01/01/2005");
		student1.setCitizenship(true);
		student1.setEmail("123@google.com");
		student1.setFatherEducation(Student.education.DEGREE);
		student1.setInstitution("UofS");
		student1.setName("Stewie Griffin");
		student1.setSIN("465467823");
		student1.setPhoneNumber("222-2222");
		student1.setMotherEducation(Student.education.HIGH_SCHOOL);
		student1.setMaritalStatus(Student.maritalStatuses.SINGLE);

		Loan loan1 = new Loan(student1);
		loan1.setAmountRequested(5000.00);
		loan1.setIsNew(true);
		student1.setLoan(loan1);

		FinancialInfo finInfo1 = new FinancialInfo();
		finInfo1.setChildSupport(0);
		finInfo1.setHouseholdIncome(100000);
		finInfo1.setPersonalIncome(10000);
		finInfo1.setScholarship(0);
		finInfo1.setTaxableEarnings(0);
		student1.setFinances(finInfo1);

		CoSigner cosigner1 = new CoSigner(789789);
		cosigner1.setName("Cleveland");
		loan1.setCosigner(cosigner1);

		dictionary.put(123456, student1);
		AddStudent myAdd = new AddStudent(student1);
		// test repeat entry
		new AddStudent(student1);

		Assert.assertTrue(myAdd.isAdded(student1));
		Assert.assertTrue(myAdd.isAdded(123456));
	}

	/**
	 * check if student was actually added and is still in dictionary
	 */
	@AfterClass
	public static void testStudentIsAdded() {
		HashMap<Integer, Student> dictionary = StudentContainer.dictionary();
		Assert.assertTrue(dictionary.containsKey(123456));
	}

}
